//
//  LiuNavigationController.swift
//  LiuWeiBo
//
//  Created by 刘晓晨 on 2017/3/26.
//  Copyright © 2017年 刘晓晨. All rights reserved.
//

import UIKit

class LiuNavigationController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        //设置边缘手势代理
        self.interactivePopGestureRecognizer?.delegate = self
        
//        navigationBar.tintColor = UIColor.black
//        navigationBar.titleTextAttributes = [NSFontAttributeName:UIFont.systemFont(ofSize: 15)]
        
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if childViewControllers.count > 0 {
            if childViewControllers.count == 1 {
                let title = childViewControllers.first?.title
                
                viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(titleStr: title!, andTarget: self, imageName:"navigationbar_back_withtext" ,action: #selector(leftItemAction))
            } else {
                viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(titleStr: "返回", andTarget: self, imageName:"navigationbar_back_withtext" ,action: #selector(leftItemAction))
            }
            
            viewController.hidesBottomBarWhenPushed = true
            
        } 

        super.pushViewController(viewController, animated: animated)
      
    }
    
    func leftItemAction() {
        
        popViewController(animated: true)
    }
    
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if childViewControllers.count == 1 {
            return false
        }
        return true
    }

}
